/*
* SMILParser
*
* Version 1.0
*
* Programmers: Jesse Louderback, Noah Pham, Chad Carpenter, and Marc Hindman
*/
package com.SmilDial;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.*;

public class TextMenu extends Activity {
	EditText inputText;
	EditText inputTextStartTime;
	EditText inputTextDurationTime;
	
	/** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.text_menu);       
        
        inputText = (EditText)findViewById(R.id.inputText);
        inputTextStartTime = (EditText)findViewById(R.id.inputStartTime);
        inputTextDurationTime = (EditText)findViewById(R.id.inputDurationTime); 
                
        Button btnNext = (Button)findViewById(R.id.btnNext);
        Button btnCancel = (Button)findViewById(R.id.btnCancel);
        
        btnNext.setOnClickListener(new View.OnClickListener() {
			
			public void onClick(View v) {
				
				Intent intent = new Intent(TextMenu.this, LoadingScreenImageMenu.class);
				
				String txtInput = "empty string";
				Float txtStartTime = (float) 0.0;
				Float txtDurationTime = (float) 0.0;
				Boolean inputGood = true;
				
				if (inputText.getText().toString().length() >= 1) {
					txtInput = inputText.getText().toString();
				}
				
				if (inputTextStartTime.getText().toString().length() >= 1) {
					inputGood = numValidationInput(inputTextStartTime.getText().toString());
					txtStartTime = new Float(inputTextStartTime.getText().toString());
				}
				
				if (inputTextDurationTime.getText().toString().length() >= 1) {
					inputGood = numValidationInput(inputTextDurationTime.getText().toString());
					txtDurationTime = new Float(inputTextDurationTime.getText().toString());
				}
				
				if (inputGood) {
					Bundle SMIL_Bundle = new Bundle();
					SMIL_Bundle.putString("txtInput", txtInput);
					SMIL_Bundle.putFloat("txtStartTime", txtStartTime);
					SMIL_Bundle.putFloat("txtDurationTime", txtDurationTime);				
					
					intent.putExtras(SMIL_Bundle);
					startActivity(intent);
				}
			}
		});
        
        btnCancel.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				startActivity(new Intent(TextMenu.this, SmilDialActivity.class));
			}
		});
    }
    
    private Boolean numValidationInput(String inputValue) {
    	try {
    		int x = Integer.parseInt(inputValue);
    		
    		return true;
    	} catch(Exception e) {
    		Toast toast=Toast.makeText(this, "Duration time must be a number.", 2000); 
    		toast.show(); 
    	}
    	
    	return false;
    }
}
